package com.wbt.bambootown.mvp.presenter;


import com.wbt.bambootown.entity.Facility;
import com.wbt.bambootown.entity.CameraDevices;
import com.wbt.bambootown.entity.Farms;
import com.wbt.bambootown.mvp.contract.HomeContract;
import com.wbt.bambootown.mvp.frame.FragmentPresenter;
import com.wbt.bambootown.mvp.model.HomeModel;
import com.wbt.bambootown.rx.FilterSubscriber;
import com.wbt.bambootown.utils.Log;

import java.util.List;

public class HomePresenter extends FragmentPresenter<HomeModel,HomeContract.View> implements HomeContract.Presenter{
    public static final String TAG = "HomePresenter";


    @Override
    public void getFarms(String id) {
        addSubscription(getModel().getFarms(id), new FilterSubscriber<List<Farms>>() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().showError("getFarms:" + errorMsg);
            }

            @Override
            public void onNext(List<Farms> farms) {
                getView().showFarmsSuccess(farms);
            }
        });
    }

    @Override
    public void getFacilities(int id) {
        addSubscription(getModel().getFacilities(id), new FilterSubscriber<List<Facility>>() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().showError("getFacilities:" + errorMsg);
            }

            @Override
            public void onNext(List<Facility> facilities) {
                getView().showFacilitiesSuccess(facilities);
            }
        });
    }

    @Override
    public void getCamera(int id) {
        addSubscription(getModel().getCameraDevices(id), new FilterSubscriber<List<CameraDevices>>() {
            @Override
            public void onError(int errorCode, String errorMsg) {
                getView().showError("getCamera:" + errorMsg);
            }

            @Override
            public void onNext(List<CameraDevices> cameraDevices) {
                getView().showCameraSuccess(cameraDevices);
            }
        });
    }
}
